const path = require("path")

const prodConfig = require("./config/webpack.prod.js")
const devConfig = require("./config/webpack.dev.js")
const {merge} = require("webpack-merge")

module.exports = (env, arg) => {
    let config = {
        entry: "./src/index.js",
        output: {
            filename: "lx.js",
            path: path.resolve(__dirname, "dist")
        },
        module: {
            rules: [{
                test: /\.css$/,
                use: ["style-loader", "css-loader"]
            }, {
                test: /\.(jpg|png|svg|gif)$/,
                // type: 'asset/source',
                use: {
                    loader: "url-loader",
                    options: {
                        limit: 10 * 1024,
                        esModule: false
                    },
                },
                type: 'javascript/auto'
            }, {
                test: /\.js$/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: ["@babel/preset-env"]
                    }
                }
            }, {
                test: /\.html$/,
                use: {
                    loader: "html-loader",
                    options: {
                        sources: {
                            list: [
                                {
                                    tag: "a",
                                    attribute: "href",
                                    type: "src"
                                },
                                {
                                    tag: "img",
                                    attribute: "src",
                                    type: "src"
                                }
                            ]
                        }
                    }
                }
            }]
        },
        mode: "none",
    }

    if (env.prod) {
        config = merge(config, prodConfig)
    }

    if (env.dev) {
        config = merge(config, devConfig)
    }
    return config

}